CC = gcc
PROF = -pg
PROF =
OUTBIN= chat
CFLAGS = -O3 -pipe -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -fno-strict-aliasing -g $(PROF) 
LINK = $(CC) -o $(OUTBIN) $(OBJECTS) $(PROF) -lm -lrt -lpthread -lc -static

CORE_DEPS =  test/hashtest.c test/listtest.c \
			core/chat_config.h \
			core/chat_log.h \
			core/chat_hash.h \
			core/chat_list.h \
			core/chat_types.h \
			os/chat_file.h \
			os/chat_epoll.h \
			logic/chat_connection.h \
			logic/chat_message.h \
			lib/md5.h \

OBJECTS = objs/main.o \
		  objs/chat_config.o \
		  objs/chat_hash.o \
		  objs/chat_list.o \
		  objs/chat_log.o \
		  objs/chat_epoll.o \
		  objs/chat_connection.o \
		  objs/chat_message.o \
		  objs/chat_file.o \
		  objs/lib_md5.o \
		  

chat : $(OBJECTS)
	  $(LINK)
	  mv ./chat ./bin/chat

objs/main.o : $(CORE_DEPS) \
		 main.c
		 $(CC) -c $(CFLAGS) \
		 -o objs/main.o \
		 main.c

objs/chat_config.o : $(CORE_DEPS) \
		 core/chat_config.c
		 $(CC) -c $(CFLAGS) \
		 -o objs/chat_config.o \
		 core/chat_config.c

objs/lib_md5.o : $(CORE_DEPS) \
		 lib/md5.c
		 $(CC) -c $(CFLAGS) \
		 -o objs/lib_md5.o \
		 lib/md5.c

objs/chat_file.o : $(CORE_DEPS) \
		 os/chat_file.c
		 $(CC) -c $(CFLAGS) \
		 -o objs/chat_file.o \
		 os/chat_file.c

objs/chat_log.o : $(CORE_DEPS) \
		 core/chat_log.c
		 $(CC) -c $(CFLAGS) \
		 -o objs/chat_log.o \
		 core/chat_log.c
		 
objs/chat_hash.o : $(CORE_DEPS) \
		 core/chat_hash.c
		 $(CC) -c $(CFLAGS) \
		 -o objs/chat_hash.o \
		 core/chat_hash.c
		 
objs/chat_list.o : $(CORE_DEPS) \
		 core/chat_list.c
		 $(CC) -c $(CFLAGS) \
		 -o objs/chat_list.o \
		 core/chat_list.c

objs/chat_epoll.o : $(CORE_DEPS) \
		 os/chat_epoll.c
		 $(CC) -c $(CFLAGS) \
		 -o objs/chat_epoll.o \
		 os/chat_epoll.c
		 
objs/chat_connection.o : $(CORE_DEPS) \
		 logic/chat_connection.c
		 $(CC) -c $(CFLAGS) \
		 -o objs/chat_connection.o \
		 logic/chat_connection.c
		 
objs/chat_message.o : $(CORE_DEPS) \
		 logic/chat_message.c
		 $(CC) -c $(CFLAGS) \
		 -o objs/chat_message.o \
		 logic/chat_message.c
		 
clean : 
		 rm ./bin/chat $(OBJECTS) 
